<!DOCTYPE html>
<html lang="en">
    <head>
            <meta charset="utf-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <meta content="Bmob,BmobCloud,bomb,BaaS,mBaaS,PaaS,Serverless,FaaS,Function as a Service,Backend as a Service,serverless computing,cloud function,后端云,bmob后端云,小程序云,小程序后端,云数据库,云存储,文件存储,云函数,云端代码,定时任务,游戏后端,游戏云,用户系统,无服务器函数,移动开发,app开发,小程序开发,云端一体化,互联网中间件" name="keywords"/>
            <meta content="国内首家专注于移动应用Serverless云服务的平台,Bmob后端云让移动开发更简单,全方位一体化的后端服务平台" name="description"/>
            
            
            
            <link rel="shortcut icon" href="../../../img/favicon.ico">
        
        <script type="text/javascript" src="//game.bmob.cn/static/doc_union.js"></script>
            <!--
            <title>快速入门 - Bmob文档中心</title>
            -->
            <title>游戏实时后端 &middot; Cocos Creator – Bmob后端云 </title>        
            
            <link href="../../../css/bootstrap-custom.min.css" rel="stylesheet">
            <link href="../../../css/font-awesome-4.5.0.css" rel="stylesheet">
            <link href="../../../css/base.css" rel="stylesheet">
            <link rel="stylesheet" href="../../../css/highlight.css">
            <link href="../../../css/agate.css" rel="stylesheet">
            <link href="../../../css/custom.css" rel="stylesheet" id="custom">
    </head>

    <body >

        <div class="navbar navbar-fixed-top" role="navigation">
    <div class="main-nav">
        <!-- Collapsed navigation -->
        <div class="navbar-header">
            <a class="navbar-brand" href="../../..">
                <!--Bmob文档中心-->
                <img src="../../../img/logo.png" alt="">
            </a>
        </div>

        <!-- Expanded navigation -->
        <div class="navbar-collapse collapse">

          <ul class="nav navbar-nav">
            
              <li class="pull-left">
                
					<a href="../../..">文档首页</a>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="">数据服务</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">数据服务 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
								<li >
									<a href="../../../data/android/">Android</a>
                                </li>
                            
                            
								<li >
									<a href="../../../data/ios/">iOS</a>
                                </li>
                            
                            
								<li >
									<a href="../../../data/csharp/">C#</a>
                                </li>
                            
                            
								<li >
									<a href="../../../data/php/">PHP</a>
                                </li>
                            
                            
								<li >
									<a href="../../../data/go/">GO</a>
                                </li>
                            
                            
								<li >
									<a href="../../../data/restful/">REST API</a>
                                </li>
                            
                            
								<li >
									<a href="../../../data/wechat_app_new/rm/">JavaScript</a>
                                </li>
                            
                            
                                <li >
                                    <a href="../../../data/cocos2d_x/">Cocos2D-X</a>
                                </li>
							
                            
								<li >
									<a href="../../../data/wechat_app/">小程序</a>
                                </li>
                            
                            
                                <li >
                                    <a href="../../../data/wechat_app_new/">快应用</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../data/wechat_app_new/">Nodejs</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../data/wechat_app_new/">Cocos Creator</a>
                                </li>
							
                            
								<li >
									<a href="../../../data/wechat_app_new/rm/">小程序(新)</a>
                                </li>
                            
                            
                                <li >
                                    <a href="../../../data/kotlin/">Kotlin</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../data/python/">Python</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="../../../cloud_function/android/">云函数</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">云函数 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
                                <li >
                                    <a href="../../../cloud_function/android/">Android</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../cloud_function/ios/">iOS</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../cloud_function/java/">Java</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../cloud_function/python/">Python</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../cloud_function/csharp/">C#</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../cloud_function/php/">PHP</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../cloud_function/javascript/">JavaScript</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../cloud_function/restful/">REST API</a>
                                </li>
							
                            
								<li >
									<a href="../../../cloud_function/web/">Web</a>
                                </li>
                            
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="../../../sms/android/">短信服务</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">短信服务 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
                                <li >
                                    <a href="../../../sms/android/">Android</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../sms/ios/">iOS</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../sms/php/">PHP</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../sms/javascript/">JavaScript</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../sms/restful/">REST API</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left active">
                
					<!--<a href="">游戏实时后端</a>-->
					<li class="dropdown active">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">游戏实时后端 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
								<li >
									<a href="../../unity/quick_start/">Unity</a>
                                </li>
                            
                            
								<li class="active">
									<a href="./">Cocos Creator</a>
                                </li>
                            
                            
								<li >
									<a href="../../wechat_games/quick_start/">微信小游戏</a>
                                </li>
                            
                            
                                <li >
                                    <a href="../../cloud_function/develop_doc/">云函数</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../classic_case/">经典案例</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="">即时通讯</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">即时通讯 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
								<li >
									<a href="../../../im/android/">Android</a>
                                </li>
                            
                            
								<li >
									<a href="../../../im/ios/">iOS</a>
                                </li>
                            
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="../../../push/android/">推送服务</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">推送服务 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
                                <li >
                                    <a href="../../../push/android/">Android</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../push/ios/">iOS</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../push/php/">PHP</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../push/javascript/">JavaScript</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../push/restful/">REST API</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li class="pull-left">
                
					<!--<a href="../../../other/common_problem/">其他</a>-->
					<li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">其他 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            
                                <li >
                                    <a href="../../../other/common_problem/">常见问题</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../other/error_code/">错误码</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../other/data_safety/">数据安全</a>
                                </li>
							
                            
                                <li >
                                    <a href="../../../other/bql/">BQL</a>
                                </li>
							
                        </ul>
                    </li>
                
              </li>
            
              <li>
                  <a href="https://www.bmob.cn/repository/index" target="_blank">知识库</a>
              </li>
              <li>
                  <a href="http://doc.bmob.cn/video/index.html" target="_blank">视频教程</a>
              </li>
            </ul>
            
        </div>
    </div>
</div>

        <div class="pagebody" id="main-wrapper">
            <div class="sidebar">
                <div class="bs-sidebar hidden-print affix well" role="complementary">

	
		
	
		
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
		
	
		
				
				
				
				
				
				
				
				
				
		
	
		
				
				
				
				
				
		
	
		
				
				
					<div class="code-title">Cocos Creator</div>
				
				
				
				
		
	
		
				
				
		
	
		
				
				
				
				
				
		
	
		
				
				
				
				
		
	


	<ul class="nav bs-sidenav">
		
			
		
			
		
			
		
			
		
			
				
					
						
					
						
							
								
									<li class="active">
										<a class="itm-l1" href="./">快速入门</a>
										
										<ul class="nav">
											
											<li class="active "><a href="#_1">注册</a>
												
											</li>
												
											<li class=""><a href="#_2">下载</a>
												
											</li>
												
											<li class=""><a href="#_3">配置</a>
												
												<ul class="nav nav-l2">
													<li><a class="itm-l2" href="#_4">游戏属性</a></li>
												</ul>
												
												<ul class="nav nav-l2">
													<li><a class="itm-l2" href="#_5">云函数</a></li>
												</ul>
												
												<ul class="nav nav-l2">
													<li><a class="itm-l2" href="#_6">服务器</a></li>
												</ul>
												
												<ul class="nav nav-l2">
													<li><a class="itm-l2" href="#appkey">AppKey</a></li>
												</ul>
												
											</li>
												
											<li class=""><a href="#_7">项目</a>
												
											</li>
												
										</ul>
										
									</li>
								
									<li class="">
										<a class="itm-l1" href="../develop_doc/">开发文档</a>
										
									</li>
								
							
						
					
						
					
						
					
						
					
				
			
		
			
		
			
		
			
		
	</ul>
</div>
            </div>
            <div class="content" role="main">
                <div class="wrap">
                    

<h2 id="_1">注册<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h2>
<p><a href="https://game.bmob.cn">官网</a></p>
<h2 id="_2">下载<a class="headerlink" href="#_2" title="Permanent link">&para;</a></h2>
<p>从 <a href="https://game.bmob.cn/download">Demo下载页面</a> 中，选择自己所擅长平台，挑选一个感兴趣的Demo</p>
<p>每个Demo包含以下内容：</p>
<ul>
<li>README.md文件，是游戏设定的概述，以及管理后台的相关配置</li>
<li>project文件夹，是Cocos Creator游戏项目</li>
<li>cloud文件夹，包含了Room.java和Player.java文件</li>
</ul>
<h2 id="_3">配置<a class="headerlink" href="#_3" title="Permanent link">&para;</a></h2>
<p><a href="https://game.bmob.cn/#/game/options">管理后台-游戏选项</a></p>
<p>请根据Demo的READ.md文件内容，在管理后台配置游戏，包括人数、是否中途加入等等</p>
<h3 id="_4">游戏属性<a class="headerlink" href="#_4" title="Permanent link">&para;</a></h3>
<p><a href="https://game.bmob.cn/#/game/attribute">管理后台-游戏属性</a></p>
<p>请根据Demo的READ.md文件内容，在管理后台配置玩家在游戏内需要同步的属性</p>
<p><em>以飞机大战为例</em>：</p>
<table>
<thead>
<tr>
<th align="center">名称</th>
<th align="center">类型</th>
<th align="center">最大值</th>
<th align="center">长度</th>
<th align="center">export</th>
<th align="center">editable</th>
<th align="center">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">isdead</td>
<td align="center">boolean</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">true</td>
<td align="center">false</td>
<td align="center">玩家是否已被淘汰</td>
</tr>
<tr>
<td align="center">position</td>
<td align="center">int[]</td>
<td align="center">65535</td>
<td align="center">2</td>
<td align="center">true</td>
<td align="center">true</td>
<td align="center">玩家x、y轴位置</td>
</tr>
<tr>
<td align="center">score</td>
<td align="center">int</td>
<td align="center">65535</td>
<td align="center">-</td>
<td align="center">true</td>
<td align="center">false</td>
<td align="center">玩家分数</td>
</tr>
</tbody>
</table>
<p>点击 <strong>发布</strong> </p>
<p><img alt="Attr" src="https://bmob-cdn-14496.b0.upaiyun.com/2018/04/10/969d75ac40a48def80e1aaab031db534.jpg" /></p>
<hr />
<h3 id="_5">云函数<a class="headerlink" href="#_5" title="Permanent link">&para;</a></h3>
<p><a href="https://game.bmob.cn/#/game/code">管理后台-云函数</a></p>
<p>在 游戏设置 &gt; 云函数 里，将下载的 <strong>cloud</strong> 文件夹内的 <strong>Player.java</strong>、<strong>Room.java</strong> 文件内容分别复制进去，都复制后再点击 <strong>发布</strong></p>
<p><em>此时可能提示<code>已经被睡眠，不下发更新指令</code>，也是更新云函数成功的表现</em></p>
<p><img alt="Cloud" src="https://bmob-cdn-14496.b0.upaiyun.com/2018/04/10/f052c8d34011d16c8095bcf9cc6af519.jpg" /></p>
<hr />
<h3 id="_6">服务器<a class="headerlink" href="#_6" title="Permanent link">&para;</a></h3>
<p>在 服务器 标签页里，<strong>启用</strong> 一台服务器</p>
<p><em>此时可能提示<code>服务器未处于睡眠状态</code>，也是启用成功的表现</em></p>
<p><em>示例图是启用中的服务器，所以显示按钮为睡眠</em></p>
<p><img alt="Server" src="https://bmob-cdn-14496.b0.upaiyun.com/2018/04/10/e94ef77840c4c89380026a27ed36d695.jpg" /></p>
<hr />
<h3 id="appkey">AppKey<a class="headerlink" href="#appkey" title="Permanent link">&para;</a></h3>
<p><a href="https://game.bmob.cn/#/game/key">管理后台-云函数</a></p>
<p>游戏设置 &gt; 应用密钥 &gt; AppKey</p>
<p><img alt="AppKey" src="https://bmob-cdn-14496.b0.upaiyun.com/2018/04/10/9e583f0140450b708063a0f598bdc99c.jpg" /></p>
<h2 id="_7">项目<a class="headerlink" href="#_7" title="Permanent link">&para;</a></h2>
<ul>
<li>将下载的 <code>zip文件</code> 解压，在Cocos导入项目</li>
<li>修改 <code>/assets/scripts/BgsDemo_Lobby.js</code> 找到 <strong>Bgs.Init</strong> 这一行，第<code>一</code>个参数修改为官网获取的 <strong>AppKey</strong></li>
<li>运行游戏，打开network抓包，创建一个房间，查看这个操作的返回结果，返回结果为<pre><code>{
    "address": "a.b.c.d", // 服务器ip
    "roomInfo": {
        "ports": {
            "websocket": efgh // 服务器端口
        },
        "rid": xxx, // 房间id
        "joinKey": yyy // 房间密匙
    }
}
</code></pre>
<ul>
<li>修改 <code>/assets/scripts/BgsDemo_Lobby.js</code> 找到 <strong>Bgs.Init</strong> 这一行，第<code>二</code>个参数修改为 <strong>ws://a.b.c.d:efgh</strong>  这样的格式</li>
<li>现在就可以运行游戏了，加入刚刚创建的房间，或者再次创建房间(通过rid、joinKey加入同一个房间)</li>
<li>生成二维码/发布体验版，测试多设备联网玩</li>
</ul>
</li>
</ul>
                </div>
            </div>
        </div>

        
            <script>var base_url = '../../..';</script>
            <script src="../../../js/jquery-1.10.2.min.js"></script>
            <script src="../../../js/bootstrap-3.0.3.min.js"></script>
            <script src="../../../js/highlight.pack.js"></script>
            <script src="../../../js/main.js"></script>
            <script src="../../../js/base.js"></script>

        <div id="go-top"><i class="fa fa-chevron-up"></i></div>
        <a href="https://docs.bmob.cn/data/Android/a_faststart/doc/index.html" id="back" target="_blank">返回 <br> 旧版</a>
    </body>

</html>